<? require("adm_header.php"); 
$lProgramVersion="1.00";
if (!file_exists("config/opt_inc.php"))
{	
	echo "<Script language=\"javascript\">";
	echo "window.location=\"adm_set.php\"";
	echo "</script>";
	echo "<p>Javascript disabled.  <a href='set.php/'>Click here to continue install</a>.</p>";
	exit;
}

$sql="select ser_program_version,ser_db_version from $service_tbl order by ser_id desc limit 1";
$r=q($sql);
$row_v=mysql_fetch_array($r);
$_SESSION["version"]=$row_v["ser_program_version"];
$lDbVersion=$row_v["ser_db_version"];
$lProgramVersion=$row_v["ser_program_version"];

// Check if global table exist, which it should
$sql="select count(tplid) as num from $template_tbl";
$res_count=q($sql);
$row_c=mysql_fetch_array($res_count);
$num_tpl=$row_c["num"];

// Create global template
if ($num_tpl<1)
	q("INSERT INTO $template_tbl (`tplid`, `name`, `del`) VALUES (1, 'GLOBAL', NULL);");

	
$sql="select count(pid) as num from $pkg_tbl";
$res_count=q($sql);
$row_c=mysql_fetch_array($res_count);
$num_packages=$row_c["num"];
	
// Create new admin user if admin table is empty
if ($num_packages<1)
{
	q("INSERT INTO `$pkg_tbl` (`pid`, `pname`, `pterm`, `pdur`, `pactive`, `pprice`, `pcurrency`, `pupload`, `pmessages`, `pchat`, `pgb`, `protation`, `pvisitor`, `pfav`, `pmatch`, `pflirts`) VALUES (99, 'Default', 1, 3, 2, 0.00, 'USD', 3, 4, 999, 1, 1, 10, 10, 10, 10)");
	q("INSERT INTO `$pkg_tbl` (`pid`, `pname`, `pterm`, `pdur`, `pactive`, `pprice`, `pcurrency`, `pupload`, `pmessages`, `pchat`, `pgb`, `protation`, `pvisitor`, `pfav`, `pmatch`, `pflirts`) VALUES (1, 'Small', 2, 30, 1, 10.00, 'USD', 5, 20, 999, 1, 1, 1, 30, 30, 30)");
	q("INSERT INTO `$pkg_tbl` (`pid`, `pname`, `pterm`, `pdur`, `pactive`, `pprice`, `pcurrency`, `pupload`, `pmessages`, `pchat`, `pgb`, `protation`, `pvisitor`, `pfav`, `pmatch`, `pflirts`) VALUES (2, 'Medium', 1, 60, 1, 25.00, 'USD', 25, 250, 999, 1, 1, 55, 55, 55, 55)");
	q("INSERT INTO `$pkg_tbl` (`pid`, `pname`, `pterm`, `pdur`, `pactive`, `pprice`, `pcurrency`, `pupload`, `pmessages`, `pchat`, `pgb`, `protation`, `pvisitor`, `pfav`, `pmatch`, `pflirts`) VALUES (3, 'Gold', 1, 90, 1, 60.00, 'USD', 200, 200, 999, 1, 1, 200, 200, 200, 200)");
	
}	
	
writeCommonAdminTable("PHP Classifieds",1);
$lTplAdminIndex = new tplLoad();
$lTplAdminIndex->assign("set_cat_sort","$set_cat_sort");
$lTplAdminIndex->assign("set_webmaster_address","$set_webmaster_address");

if ($set_li)
{
	
	$lString=checkValid();
	$lTplAdminIndex->assign("li","$set_li");
	
	if (eregi("No commercial licence",$lString))
	{
		//echo "<font color='red'>Not Valid License ($li)</font><br /><a href='licence.php'>Read License Term</a>";	
		$lTplAdminIndex->assign("NOT_VALID",1);
	}
	elseif (eregi("Valid licence",$lString))
	{
		//echo "<font color='green'>Valid License ($li)</font><br /><a href='licence.php'>Read License Term</a>";	
		$_SESSION["v"]="1";
	}
	
	
	if (!ini_get("allow_url_fopen"))
	{
		/*echo "<p><font color='red'>Info</font><br />We could not validate your license since you 
		have the php setting allow_url_fopen disabled. However, you will have access to all features, unless
		fopen command is used anywhere else in the script.</p>";	*/
		$lTplAdminIndex->assign("NOT_VALID",2);
	}
}
else 
{
	//echo "<font color='red'>Only non-commercial/non-profit usage allowed</font><br /><a href='licence.php'>Read License Term</a>";
	$lTplAdminIndex->assign("NOT_VALID",3);
}


if (ini_get('magic_quotes_gpc'))
	$lTplAdminIndex->assign("MAGIC_STATUS","<font color='green'><b>".LA_ADMIN_ON."</b></font>");
else 
	$lTplAdminIndex->assign("MAGIC_STATUS","<font color='red'><b>".LA_ADMIN_OFF."</b> (".LA_MUST_FIX.")</font>");

if (ini_get('register_globals'))
	$lTplAdminIndex->assign("REGISTER_STATUS","<font color='red'><b>".LA_ADMIN_ON."</b> (".LA_MUST_FIX.")</font>");
else 
	$lTplAdminIndex->assign("REGISTER_STATUS","<font color='green'><b>".LA_ADMIN_OFF."</b></font>");

if (ini_get('safe_mode'))
	$lTplAdminIndex->assign("SAFE_STATUS","<font color='red'><b>".LA_ADMIN_ON."</b> (".LA_MUST_FIX.")</font>");
else 
	$lTplAdminIndex->assign("SAFE_STATUS","<font color='green'><b>".LA_ADMIN_OFF."</b></font>");
		
$sql = "select ad_id from $ads_tbl";	
$res = q($sql);
$lNumAds = mysql_num_rows($res);

$sql = "select user_email from $usr_tbl";	
$res2 = q($sql);
$lNumUsers = mysql_num_rows($res2);

$sql = "select id from $pic_tbl";	
$res3 = q($sql);
$lNumImgs = mysql_num_rows($res3);

if ($set_validation)
{
	$sql = "select * from $ads_tbl where (ad_is_validated = '0' OR ad_is_validated IS NULL)";	
	$res = q($sql);
	$lNumAwaitingAd = mysql_num_rows($res);
}
if ($set_approve_mem)
{
	$sql = "select * from $usr_tbl where user_approved=0";	
	$res = q($sql);
	$lNumAwaitingUser = mysql_num_rows($res);
}


$lRes=q("SELECT VERSION() as mysql_version");
$lRowVersion=mysql_fetch_array($lRes);
$lMySQLVersion=$lRowVersion["mysql_version"];
$lMySQLVersionArray=split("\.",$lMySQLVersion);

/*
foreach ($lMySQLVersionArray as $lItem)
{
		$lNum=round($lItem);
		$lVerArray[]=$lNum;
}
$lMajor=$lVerArray[0];
$lSub=$lVerArray[1];
if ($lMajor !=5)
{
	if ($lMajor==4 && $lSub==0)
		$lSkipUTF=1;
	if ($lMajor==3)
		$lSkipUTF=1;
}

if ($lSkipUTF==1)
{
	echo "<p>You have a MYSQL version ($lMySQLVersion) that doesn't support UTF8 character set. Upgrade to v4.1 or 5.x <strong>if</strong> you have non-latin characters in your language.</p>";
}
elseif ($lMajor==4)
{
	echo "<p>You have MySQL version $lMySQLVersion. We reccomend MySQL version 5.0 and higher due to speed improvements and functionality.</p>";
}
*/


$lTplAdminIndex->assign("li",$set_li);	
$lTplAdminIndex->assign("SHOP_VERSION",$lProgramVersion);
$lTplAdminIndex->assign("SHOPDB_VERSION",$lDbVersion);
$lTplAdminIndex->assign("PHP_VERSION",phpversion());		
$lTplAdminIndex->assign("MYSQL_VERSION",$lMySQLVersion);		
$lTplAdminIndex->assign("CWD",getcwd());	
$lTplAdminIndex->assign("PHP_SETTINGS",$lStr);		
$lTplAdminIndex->assign("NUM_ADS",$lNumAds);		
$lTplAdminIndex->assign("NUM_USERS",$lNumUsers);		
$lTplAdminIndex->assign("NUM_IMGS",$lNumImgs);		
$lTplAdminIndex->assign("NUM_ADS_AWAITING",$lNumAwaitingAd);			
$lTplAdminIndex->assign("NUM_USERS_AWAITING",$lNumAwaitingUser);				

$lTplAdminIndex->display("adm_index.tpl");
writeCommonAdminTable("","");
require("adm_footer.php"); 
?>
